package top.rainbowecho.article.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import top.rainbowecho.article.mapper.LikeMapper;
import top.rainbowecho.article.service.ILikeService;
import top.rainbowecho.article.vo.ArticleLikeVo;
import top.rainbowecho.model.percona.Like;

import javax.annotation.Resource;
import java.time.LocalDateTime;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 杨健
 * @since 2020-07-25
 */
@Service
public class LikeServiceImpl extends ServiceImpl<LikeMapper, Like> implements ILikeService {
    @Resource
    private LikeMapper likeMapper;

    /**
     * 用户点赞
     *
     * @param likeVo
     */
    @Override
    public void insertRecord(ArticleLikeVo likeVo) {
        Like like = new Like().setArticleId(likeVo.getArticleId())
                .setUserId(likeVo.getUserId())
                .setCreateTime(LocalDateTime.now());
        this.likeMapper.insertRecord(like);
    }

    /**
     * 取消对某篇文章的点赞
     *
     * @param likeVo
     * @return 受影响的行数
     */
    @Override
    public int unlikeArticle(ArticleLikeVo likeVo) {
        return this.likeMapper.remove(likeVo);
    }
}
